import Service from '../../core/baseService';

export default class AttrService extends Service {
  constructor(ctx) {
    super(ctx);
    this.model = ctx.sassmodel.AttrKey;
  }

  async index(page = 1, pageSize = 20, query) {
    const result: any = await this.model
      .findAndCountAll({
        where: query,
        include: [
          {
            model: this.ctx.model.AttrVal,
          },
          {
            attributes: ['name'],
            model: this.ctx.model.GoodsType,
          }
        ],
        offset: (Number(page) - 1) * pageSize,
        limit: pageSize,
        order: [['id', 'DESC']],
      });
    return {
      list: result.rows,
      total: result.count,
      page,
      pageSize,
    }
  };

}
